package com.hpeu_12.day1222;

import java.util.Scanner;

/**
 * 第四题：从键盘输入8个整数，然后将奇数和偶数分别存入到两个不同的一维数组中打印出来。
效果如下：奇数：1 3 5 7
          偶数：2 4 6 8
 * @author Administrator
 *
 */
public class HomeWork04 {

	public static void main(String[] args) {
		System.out.println("请输入8个整数:");
		Scanner scanner = new Scanner(System.in);
		int count[] = new int[8];
		int x=0,y=0;
		for (int i = 0; i < count.length; i++) {//输入8个整数
			count[i]=scanner.nextInt();
		}
		for (int j = 0; j < count.length; j++) {//获取奇数偶数各个的数组大小
			if (count[j]%2==0) {
				x++;
			}else {
				y++;
			}
			
		}
		int number1[] = new int[x];//奇数
		int number2[] = new int[y];//偶数
		int a=0;
		int b=0;
		for (int k = 0; k < count.length; k++) {
			if (count[k]%2==0) {
				number1[a]=count[k];//把偶数存入number1数组中
				a++;
			}else {
				number2[b]=count[k];//把奇数存入number1数组中
				b++;
			}
		}
		System.out.print("奇数:");
		for(int oddnumber:number2) {
			System.out.print(oddnumber+" ");
		}
		System.out.println("");
		System.out.print("偶数:");
		for(int evennumber:number1) {
			System.out.print(+evennumber+" ");
		}
	}

}
